package com.xing.util;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

//回调消息处理类
public class OnMessageCallback implements MqttCallback {

    public void connectionLost(Throwable throwable) {
        //连接丢失后，一般在这里进行重连
        System.out.println("连接断开，可以重新连接");
    }

    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
        //订阅subscribe后的消息会执行到这里面
        System.out.println("接收消息主题："+topic);
        System.out.println("接收消息服务质量等级Qos:"+mqttMessage.getQos());
        System.out.println("接收消息内容："+new String(mqttMessage.getPayload()));

    }

    //发送完成
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        System.out.println("deliveryComplete发送完成：=======》"+iMqttDeliveryToken.isComplete());

    }
}
